Home:ALL Converter>Get count of true in bool[,] F#

Get count of true in bool[,] F#

Ask Time:2014-08-01T14:03:19         Author:BBH1023

Json Formatter

I have a bool[,] in F# and I want to get the count of true 's present. How can i do this without descending into imperative programming?

this is my current solution, which is really just c# written in f#.

let mutable x = 0
for cell in cells do
    if cell = true then x <- x + 1
x

Author:BBH1023,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25073810/get-count-of-true-in-bool-f
MisterMetaphor :

Here's one way:\n\nlet x = cells |> Seq.cast |> Seq.filter id |> Seq.length\n\n\nWhat it does is filters out false values (see Seq.filter), and then just counts what's left.",
2014-08-01T06:26:17
yy